package Zoo.Handler;




import Zoo.View.LeaderView.AddZooparkView;
import Zoo.View.LeaderView.DeleteZooparkView;
import Zoo.View.LeaderView.LeaderView;
import Zoo.View.LeaderView.UpdateZooparkView;


import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LeaderViewHandler implements ActionListener {
    private LeaderView leaderView;

    public JTable getjTable() {
        return jTable;
    }

    public void setjTable(JTable jTable) {
        this.jTable = jTable;
    }

    private JTable jTable;

    /**
     * 园长所看到的园区主界面的增删改查功能
     * @param leaderView
     */

    public LeaderViewHandler(LeaderView leaderView){
        this.leaderView=leaderView;
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton=(JButton) e.getSource();
        String text =jButton.getText();
        if("增加".equals(text)){
             new AddZooparkView(leaderView);
//                new AddUserView(LeaderViewHandler);
        }else if("修改".equals(text)){
//            int[] selectedZooparkId=leaderView.getSelectZooparkId(jTable);
//            if(selectedZooparkId.length!=1){
//                JOptionPane.showMessageDialog(leaderView,"一次只能修改一行！");
//                return;
//            }
            //selectedZooparkId[0]就是修改的原园区id
          new UpdateZooparkView(leaderView);

        }else if("删除".equals(text)){
//            int[] selectedZooparkIds=leaderView.getSelectZooparkId(jTable);
//            if(selectedZooparkIds.length==0){
//                JOptionPane.showMessageDialog(leaderView,"请选择要删除的行！");
//                return;
//            }
//            int option = JOptionPane.showConfirmDialog(leaderView, "你确认要删除选择的" +
//                    selectedZooparkIds.length + "行吗？", "确认删除", JOptionPane.YES_NO_OPTION);
//            if(option==JOptionPane.YES_OPTION){  //确认
//                //执行删除
//                LeaderService leaderService=new LeaderServiceImpl();
//                boolean deleteResult =leaderService.delete(selectedZooparkIds);
//                if(deleteResult){
//                    //重新加载表格查到最新数据
//                    leaderView.reloadTable();
//                }else{
//                    JOptionPane.showMessageDialog(leaderView,"删除失败");
//                }
//            }



            new DeleteZooparkView(leaderView);
        }else if("查询".equals(text)){
//            LeaderViewHandler.setPageNow(1);
            leaderView.reloadTable();

        }
    }

}
